/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.base.mapreduce;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.WritableComparable;

/**
 *
 * @author nastya
 */
public class UserValuePair implements WritableComparable<UserValuePair> {
    private long value;
    private byte[] user;

    public UserValuePair() {
    }

    public UserValuePair(long value, byte[] user) {
        this.value = value;
        this.user = user;
    }

    public byte[] getUser() {
        return user;
    }

    public long getValue() {
        return value;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        String userS = Bytes.toString(user);
        out.writeUTF(userS);
        out.writeLong(value);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        String userS = in.readUTF();
        this.user = Bytes.toBytes(userS);
        this.value = in.readLong();
    }

    @Override
    public int compareTo(UserValuePair t) {
        if (t == null) {
            return 1;
        }
        String a1 = Bytes.toString(user);
        String a2 = Bytes.toString(t.user);
        return a1.compareTo(a2);
    }
    
}
